import {
  BaseCommand,
  cmdInvoker,
  MenuItemDefinition,
  Types,
} from '@amcax/base';
import { cmdCircularArray } from '@app-base/environments/product/commands/cmd-array-circle';
import { cmdLinearArray } from '@app-base/environments/product/commands/cmd-array-linear';
import { cmdCopyPart } from '@app-base/environments/product/commands/cmd-copy';
import { cmdTransformPart } from '@app-base/environments/product/commands/cmd-transform';
import { ctx2 } from '@app-cad/module';
import { ProductTreeNode } from '../../types';

const commandsPreventingHide: BaseCommand['id'][] = [
  cmdCircularArray.id,
  cmdCopyPart.id,
  cmdLinearArray.id,
  cmdTransformPart.id,
];

export const hide: MenuItemDefinition<ProductTreeNode> = {
  id: 'hide',
  children: '隐藏',
  disabled: () => commandsPreventingHide.includes(cmdInvoker.currentCmd?.id),
  hidden: ({ props }) =>
    !props.parent || // root node has no parent
    Array.isArray(props) ||
    !props?.visible ||
    [
      'assembly-constraint',
      'assembly-constraints-root',
      'measurement-root',
      Types.FRAME,
      Types.PLANE,
    ].includes(props?.type),
  onClick: async ({ props: node }) => {
    if (![Types.BASIC_PLANE, Types.ORIGIN].includes(node.type as Types)) {
      await ctx2.commandCenters.basicCommands.setVisibility(node.key, false);
    }
  },
};
